# For a detailed tutorial type vignette("harmonicmeanp")
# Example: simulate from a non-uniform distribution mildly enriched for small \emph{p}-values.
# Compare the significance of the combined p-value for Bonferroni, Benjamini-Hochberg (i.e. Simes),
# HMP and (equivalently) MAMML with 2 degrees of freedom.
L = 1000
p = rbeta(L,1/1.5,1)
min(p.adjust(p,"bonferroni"))
min(p.adjust(p,"BH"))
x = hmp.stat(p)
pharmonicmeanp(x,length(p))
p.hmp(p,L=L)
p.mamml(1/p,2,L=L)
# Compute critical values for the HMP from asymptotic theory and compare to direct simulations
L = 100
alpha = 0.05
(hmp.crit = qharmonicmeanp(alpha,L))
nsim = 100000
p.direct = matrix(runif(L*nsim),nsim,L)
hmp.direct = apply(p.direct,1,hmp.stat)
(hmp.crit.sim = quantile(hmp.direct,alpha))
# Compare HMP of p-values simulated directly, and via the asymptotic distribution,
# to the asymptotic density
L = 30
nsim = 10000
p.direct = matrix(runif(L*nsim),nsim,L)
hmp.direct = apply(p.direct,1,hmp.stat)
hmp.asympt = rharmonicmeanp(nsim,L)
h = hist(hmp.direct,60,col="green3",prob=TRUE,main="Distributions of harmonic mean p-values")
hist(hmp.asympt,c(-Inf,h$breaks,Inf),col="yellow2",prob=TRUE,add=TRUE)
hist(hmp.direct,60,col=NULL,prob=TRUE,add=TRUE)
curve(dharmonicmeanp(x,L),lwd=2,col="red3",add=TRUE)
legend("topright",c("Direct simulation","Asymptotic simulation","Asymptotic density"),
fill=c("green3","yellow2",NA),col=c(NA,NA,"red3"),lwd=c(NA,NA,2),bty="n",border=c(1,1,NA))
Run the code above in your browser using DataLab